home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8235 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  963 b 

  1. Path: cs.tu-berlin.de!news
  2. From: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Problem with a for loop
  5. Date: 2 Mar 1996 16:31:09 GMT
  6. Organization: Technical University of Berlin, Germany
  7. Message-ID: <4h9t4d$gjl@news.cs.tu-berlin.de>
  8. NNTP-Posting-Host: 130.149.17.226
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=iso-8859-1
  11. Content-Transfer-Encoding: 8bit
  12.  
  13. ksexton@wilde.oit.umass.edu (Kevin M Sexton) writes:
  14. > Hi.
  15. > I was doing a project for one of my classes and I came across a rather 
  16. > odd bug in part of the code.  I initially had the following:
  17. > for ( i = 0; WL[i] != NULL, i <= 10; i++ )
  18. > {
  19. >     AAL[i] = new char[strlen(WL[i])+1);
  20. >     strcpy(AAL[i], WL[i]);
  21. > }
  22.  
  23. You have to change your condition to WL[i]!=NULL && i<=10. The comma 
  24. operator evaluates the first expression( WL[i]!=NULL ), then the second
  25. ( i<=10 ) and return the value of the second. Thus, you loop is always
  26. executed until i==11.
  27.  
  28. Bye
  29.  
  30. Roman
  31.